tare_mode

Owner: You

Purpose and Documentation

This function will set the zero point of the scales. It should be able to read the settings register and determine what mode (ie, REMOTE/LOCAL) it is in, and give appropriate output to the peripherals. It will store the zero value into the settings module for use by other functions.

Syntax

int tare_mode(void)

Usage

Tare mode is availiable at all times. The function change_operating_state will invoke it when the user requests it.

Input Arguments

  • void. This function takes no arguments.

Output Arguments

  • None. This function does not make changes to any existing values.

Return Value

  • int. This is an error code to check if the operation could be completed successfully. A 0 indicates normal behaviour.

Settings and Registers

Read

  • int Settings.enabled_outputs.

Write

  • long int Settings.zero.

Operation

The program will output that it is performing a tare operation. It will then run calculate_mass in absolute terms (ie, zero = 0) to get the current reading from the scales. It will then set the value of Settings.zero in the settings register. *An improvement to this might do several checks to make sure that the zero value about to be written is appropriate - ie, it will wait for the scales to stabalise properly.

Code

int tare_mode(void)
{
  const char[] message1 = "Re-zeroing. Please do not touch the scales."
  const char[] message2 = "Re-zero complete."
  //Inform the user that the scales are being re-zeroed.
  switch(Settings.enabled_outputs())
  {
    case SERIALOUT: transmit(message1); break;
    case LCDOUT: display(message1); break;
    case UNMUTE: speak(message1); break;
    default: transmit("UNDEFINED SETTINGS"); return -1;
  }
  //Measure the mass currently on the scales.
  Settings.zero = calculate_mass(0, cal_values);
  //Inform the user that the tare is complete.
  switch(Settings.enabled_outputs())
  {
    case SERIALOUT: transmit(message2); break;
    case LCDOUT: display(message2); break;
    case UNMUTE: speak(message2); break;
    default: transmit("UNDEFINED SETTINGS"); return -1;
  }
  return 0;
}